#ifndef _MAIN_
#define _MAIN_

#include <map>
#include <string>
#include "Sniffer.h"
#include "SessionTracker.h"
#include "Parser.h"
#include "SharedQueue.h"
#include "SwafStructs.h"
SharedQueue<struct RAWIPDATA> snifferQ;
map<string,struct HTTP_SESSION> httpSessionsTable;

int numSniffedPackets=0;

void Sniffer_func();
void Session_Tracker_func();
void Parser_func();
void print();


int main()
{
	const int WAIT = 1;


	thread SnifferThr(&Sniffer_func);
	thread SessTrkThr(&Session_Tracker_func);
	thread ParsThr(&Parser_func);
	//thread printThr(&print);

	SnifferThr.join();
	SessTrkThr.join();
	ParsThr.join();
	//printThr.join();

	return 0;
}

void Sniffer_func()
{
	std::cout<<"\n ***** Start Sniffer *****\n"<<endl;
	Sniffer sniff(&snifferQ);
	sniff.init();
	sniff.runSniffer();
}

void Session_Tracker_func()
{
	std::cout<<"\n ***** Start Sessions_Tracker *****\n"<<endl;
	SessionTracker sess(&snifferQ,&httpSessionsTable);
	sess.init();
	sess.run();
}

void Parser_func()
{
	std::cout<<"\n ***** Start Parser *****\n"<<endl;
	Parser pars(&httpSessionsTable);
	pars.init();
	pars.run();
}

void print() // For Debug
{
	std::cout<<"\n ***** Start PRINT (DEBUG) *****\n"<<endl;
	SessionTracker sess(&snifferQ,&httpSessionsTable);
	string str;

	while(1)
	{
		cin >> str;
		system("clear");
		sess.printSessionsToFile();
		exit(0);
	}
}

#endif//_MAIN_




















